﻿package mortal.common.swfPlayer.frames
{
    import com.gengine.core.call.*;
    import com.gengine.debug.*;
    import com.gengine.resource.*;
    import com.gengine.resource.info.*;
    import flash.display.*;
    import flash.utils.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.game.scene3D.player.info.*;

    public class SwfFrames extends Object
    {
        private var _actionFrams:Dictionary;
        public var fireFrame:int = 2;
        private var _name:String;
        private var _frameType:String;
        private var _modleInfo:IModelInfo;
        private var _isLoaded:Boolean;
        protected var _isLoading:Boolean;
        protected var _url:String;
        protected var _caller:Caller;
        protected var _callType:String = "type";
        private var _referenceCount:int = 0;
        public var isInitEmptyFrames:Boolean = false;
        private var _key:String;
        private var _disposeTime:Number = 0;
        private var _type:int = 1;
        private var _pointY:Number = 0;
        private var _modleType:int;
        private var _isSouthTop:Boolean = false;
        private var _isNorthTop:Boolean = false;
        private var _swfInfo:SWFInfo;
        private var _loadPriority:int = 2;
        private var _modle:Object;
        public var loadCompleteHandler:Function;
        private var _actionConut:int;
        public var isClear:Boolean = true;
        public static var swfUrl:Dictionary = new Dictionary();
        private static const DisposeTime:Number = 20000;

        public function SwfFrames(param1:String, param2:String)
        {
            this._actionFrams = new Dictionary();
            this._frameType = param1;
            this._name = param2;
            this._caller = new Caller();
            return;
        }// end function

        public function get loadPriority() : int
        {
            return this._loadPriority;
        }// end function

        public function set loadPriority(param1:int) : void
        {
            this._loadPriority = param1;
            return;
        }// end function

        public function get modleType() : int
        {
            return this._modleType;
        }// end function

        public function set modleType(param1:int) : void
        {
            this._modleType = param1;
            return;
        }// end function

        public function get isSouthTop() : Boolean
        {
            return this._isSouthTop;
        }// end function

        public function set isSouthTop(param1:Boolean) : void
        {
            this._isSouthTop = param1;
            return;
        }// end function

        public function get isNorthTop() : Boolean
        {
            return this._isNorthTop;
        }// end function

        public function set isNorthTop(param1:Boolean) : void
        {
            this._isNorthTop = param1;
            return;
        }// end function

        public function get pointY() : Number
        {
            return this._pointY;
        }// end function

        public function set pointY(param1:Number) : void
        {
            this._pointY = param1;
            return;
        }// end function

        public function get type() : int
        {
            return this._type;
        }// end function

        public function get isLoaded() : Boolean
        {
            return this._isLoaded;
        }// end function

        public function get url() : String
        {
            return this._url;
        }// end function

        public function get disposeTime() : Number
        {
            return this._disposeTime;
        }// end function

        public function get actionConut() : int
        {
            return this._actionConut;
        }// end function

        public function set actionConut(param1:int) : void
        {
            this._actionConut = param1;
            return;
        }// end function

        public function get key() : String
        {
            if (this._key == null)
            {
                this._key = getSwfKey(this.name, this.frameType);
            }
            return this._key;
        }// end function

        public function get name() : String
        {
            return this._name;
        }// end function

        public function set name(param1:String) : void
        {
            this._name = param1;
            return;
        }// end function

        public function set modleInfo(param1:IModelInfo) : void
        {
            this._modleInfo = param1;
            return;
        }// end function

        public function get frameType() : String
        {
            return this._frameType;
        }// end function

        public function set movieClip(param1:MovieClip) : void
        {
            var _loc_3:ActionInfo = null;
            if (param1 == null)
            {
                if (this.isInitEmptyFrames == false)
                {
                    return;
                }
            }
            var _loc_2:Array = [];
            for each (_loc_3 in this._actionFrams)
            {
                
                _loc_3.movieClip = param1;
            }
            return;
        }// end function

        public function get movieClip() : MovieClip
        {
            if (this._swfInfo)
            {
                return this._swfInfo.clip;
            }
            return null;
        }// end function

        public function createEmptyMovieClip() : void
        {
            var _loc_1:ActionInfo = null;
            for each (_loc_1 in this._actionFrams)
            {
                
                _loc_1.movieClip = null;
            }
            return;
        }// end function

        public function removeReference() : void
        {
            var _loc_1:String = this;
            var _loc_2:* = this._referenceCount - 1;
            _loc_1._referenceCount = _loc_2;
            if (this._referenceCount <= 0)
            {
                if (this._url && !this._isLoaded && !this._isLoading)
                {
                    this._isLoaded = false;
                    this._isLoading = false;
                    LoaderManager.instance.removeNotLoadedFile(this._url);
                    delete swfUrl[this.url];
                    this._disposeTime = 0;
                }
                else
                {
                    this._disposeTime = getTimer() + DisposeTime;
                }
            }
            if (this._referenceCount <= 0)
            {
                this.clearFromLoad();
            }
            return;
        }// end function

        public function addReference() : void
        {
            if (this._referenceCount < 0)
            {
                this._referenceCount = 0;
            }
            var _loc_1:String = this;
            var _loc_2:* = this._referenceCount + 1;
            _loc_1._referenceCount = _loc_2;
            return;
        }// end function

        public function get referenceCount() : int
        {
            return this._referenceCount;
        }// end function

        public function clearReferenceCount() : void
        {
            this._referenceCount = 1;
            this.removeReference();
            return;
        }// end function

        public function load(param1:String, param2:Function) : void
        {
            this.addReference();
            this._url = param1;
            if (this._isLoaded)
            {
                if (param2 is Function)
                {
                    this.param2(this);
                }
                return;
            }
            if (this._isLoading)
            {
                if (param2 is Function)
                {
                    this._caller.addCall(this._callType, param2);
                }
            }
            else
            {
                if (param2 is Function)
                {
                    this._caller.addCall(this._callType, param2);
                }
                this._isLoading = true;
                swfUrl[param1] = true;
                LoaderManager.instance.load(param1, this.onModelLoaded, this._loadPriority);
            }
            return;
        }// end function

        protected function onModelLoaded(param1:SWFInfo) : void
        {
            this._swfInfo = param1;
            this._isLoaded = true;
            this._isLoading = false;
            this.movieClip = param1.clip;
            this._caller.call(this._callType, this);
            this._caller.removeCallByType(this._callType);
            if (this.loadCompleteHandler is Function)
            {
                this.loadCompleteHandler();
            }
            return;
        }// end function

        public function getFrames(param1:int, param2:int) : FrameArray
        {
            var _loc_3:* = this._actionFrams[param1];
            if (_loc_3)
            {
                if (_loc_3.dir == 1)
                {
                    param2 = DirectionType.DefaultDir;
                }
                return _loc_3.getActionDir(param2);
            }
            return null;
        }// end function

        private function addAction(param1:ActionInfo) : void
        {
            this._actionFrams[param1.action] = param1;
            return;
        }// end function

        public function getActionInfo(param1:int) : ActionInfo
        {
            return this._actionFrams[param1];
        }// end function

        public function clone() : SwfFrames
        {
            var _loc_1:* = new SwfFrames(this._frameType, this._name);
            _loc_1.createAction(this._modle);
            return _loc_1;
        }// end function

        public function createAction(param1:Object) : void
        {
            var _loc_2:Object = null;
            var _loc_3:ActionInfo = null;
            var _loc_4:Array = null;
            this._modle = param1;
            this.fireFrame = param1.fireFrame;
            this._type = param1.type;
            this.isInitEmptyFrames = param1.isInitEmptyFrames;
            if (param1.action is Array)
            {
                _loc_4 = param1.action as Array;
                this._actionConut = _loc_4.length;
                for each (_loc_2 in _loc_4)
                {
                    
                    _loc_3 = new ActionInfo(_loc_2.type, _loc_2.startFrame, _loc_2.endFrame, _loc_2.frameRate, _loc_2.delay, _loc_2.dir);
                    _loc_3.isInitEmptyFrames = _loc_2.isInitEmptyFrames;
                    _loc_3.swf = this;
                    this.addAction(_loc_3);
                    var _loc_7:String = this;
                    var _loc_8:* = this._actionConut + 1;
                    _loc_7._actionConut = _loc_8;
                }
            }
            else
            {
                _loc_2 = param1.action;
                _loc_3 = new ActionInfo(_loc_2.type, _loc_2.startFrame, _loc_2.endFrame, _loc_2.frameRate, _loc_2.delay, _loc_2.dir);
                _loc_3.isInitEmptyFrames = _loc_2.isInitEmptyFrames;
                _loc_3.swf = this;
                this.addAction(_loc_3);
                this._actionConut = 1;
            }
            return;
        }// end function

        public function dispose() : void
        {
            var _loc_1:ActionInfo = null;
            if (this.isClear == false)
            {
                return;
            }
            this._referenceCount = -1;
            this._isLoaded = false;
            this._isLoading = false;
            this.clearFromLoad();
            for each (_loc_1 in this._actionFrams)
            {
                
                _loc_1.dispose();
            }
            delete swfUrl[this.url];
            if (this._swfInfo)
            {
                this._swfInfo.dispose();
            }
            return;
        }// end function

        private function clearFromLoad() : void
        {
            return;
        }// end function

        public static function getSwfKey(param1:String, param2:String) : String
        {
            return param2 + "_" + param1;
        }// end function

        public static function traceUrl() : void
        {
            var _loc_2:* = undefined;
            var _loc_1:String = "";
            for (_loc_2 in swfUrl)
            {
                
                _loc_1 = _loc_1 + (_loc_2 + "|");
            }
            Log.debug("未销毁的swfUrl:" + _loc_1);
            return;
        }// end function

        public static function isDispose(param1:String) : Boolean
        {
            return param1 in swfUrl;
        }// end function

    }
}
